#ifndef E8409DAF_239A_4EFD_86AA_AA36C8AFDDE3
#define E8409DAF_239A_4EFD_86AA_AA36C8AFDDE3

#include <iostream>
using namespace std;
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string>


const string filename = "./myfile";
const int proj_id = 126;
const int size = 1024;

key_t GetKey()
{
    key_t key = ftok(filename.c_str(), proj_id);
    if (key == -1)
    {
        cerr << "获取Key失败" << endl;
        exit(-1);
    }
    return key;
}

int CreateMemory(int flag)
{
    key_t key = GetKey(); /*获取key*/
    int shmid = shmget(key, size, flag);
    if (shmid == -1)
    {
        cerr << "创建共享内存失败" << endl;
        exit(-1);
    }

    return shmid;
}

int GreatShm()
{
    return CreateMemory(IPC_CREAT | IPC_EXCL | 0666);
}

int GetShm()
{
    return CreateMemory(IPC_CREAT);
}

#endif /* E8409DAF_239A_4EFD_86AA_AA36C8AFDDE3 */
